package org.ucn.dmaa0914.temadesign.group2;


/**
 * StringUtil provides some small utility functions
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class StringUtil
{
    public static String repeatString(String str, int cnt)
    {
        String result = "";
        
        for( int i = 0; i < cnt; ++i )
        {
            result += str;
        }
        
        return result;
    }
    
    /**
     * Sorrounds the given string with whitespace, while keeping the string in the center.
     */
    public static String centerAlign(String str, int targetLength)
    {
        int spacesTotal = (targetLength - str.length());
        int spacesLeft = spacesTotal / 2;
        int spacesRight = spacesTotal - spacesLeft;
        return repeatString(" ", spacesLeft) + str + repeatString(" ", spacesRight);
    }
}
